#pragma once
#include "web/pch.h"

namespace Web
{
	struct Thread
	{
		std::unique_ptr<std::thread> m_Thread;

		virtual void Run() = 0;

		virtual ~Thread() = default;

		static void RunTask(Web::Thread* _Ptr)
		{
			_Ptr->Run();
		}
		void Start()
		{
			m_Thread = std::make_unique<std::thread>(&Thread::RunTask, this);
		}

		std::thread::id GetId() const
		{
			assert(m_Thread);
			return m_Thread->get_id();
		}

		std::thread::native_handle_type GetHandleType() const
		{
			assert(m_Thread);
			return m_Thread->native_handle();
		}

		void Detach()
		{
			if (m_Thread && m_Thread->joinable())
				m_Thread->detach();
		}

		void Join()
		{
			if (m_Thread && m_Thread->joinable())
				m_Thread->join();
		}

		bool Joinable() const
		{
			return m_Thread && m_Thread->joinable();
		}

		static unsigned int HardwareConcurrency()
		{
			return std::thread::hardware_concurrency();
		}

		//Thread(const Thread&) = delete;
		//Thread& operator=(const Thread&) = delete;
		//Thread(Thread&&) = default;
		//Thread& operator=(Thread&&) = default;
	};
}
